package com.qf.JDBC;

import java.sql.*;
import java.util.Scanner;

/**
 * @author wangyu
 * @Classname: loginjdbc
 * @Description: TEST
 * @date 2022-04-04 13:31
 */
public class loginjdbc2 {
    public static void main(String[] args) throws  Exception{
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入用户名");
        String userName = scanner.nextLine();
        System.out.println("输入密码");
        String password = scanner.nextLine();

        Connection connection = DBUtitls.getConnection();
//        获得preparedStatement 对象
        PreparedStatement preparedStatement =  connection.prepareStatement("select * from user where userName=? and userpassword=?;");

//        System.out.println(preparedStatement);
//        赋值
        preparedStatement.setString(1,userName);
        preparedStatement.setString(2,password);

//        执行语句
        ResultSet resultSet = preparedStatement.executeQuery();
        if(resultSet.next()){
            System.out.println("成功");
        }else {
            System.out.println("失败");
        }

//        关闭
        DBUtitls.closeAll(connection,preparedStatement,resultSet);
    }
}
